<!--
 * @name warnUp
 * @description 组件描述
 * @author idouya
 * @email elegentfrog@163.com
 * @date 2025-07-01
 -->

<template>
  <div class="p-warn-up common-bg common-layout">
    <page-title
      :discipline="gameInfo.discipline"
      :event="gameInfo.event"
      :match="gameInfo.match"
      :type="gameInfo.type"
      :eventName="gameInfo.eventName"
      :startTime="gameInfo.startTime"
    ></page-title>
    <div class="conetnt">
      <div class="info">{{ irm }}</div>
    </div>
  </div>
</template>

<script setup>
import useStore from '@/store'
import Storage from '@/assets/js/storage'
import Utils from '@/assets/js/utils'
import Config from '@/assets/js/config'
import PageTitle from '@/components/scb/PageTitle.vue'
import { useMultiProcRequest } from '@/assets/js/useMultiProcRequest'

const { results, fetchForProcs } = useMultiProcRequest()

const { proxy } = getCurrentInstance()
const router = useRouter()
const route = useRoute()

const gameInfo = ref({
  discipline: '马术',
  match: '',
  event: 'JUMPINDV',
  type: '实时成绩',
  eventName: '',
})

const params = ref({})
const procName = ref([])

const irm = ref()
const commonStore = useStore.useCommonStore()

onBeforeMount(() => {})
onMounted(() => {
  params.value = route.query
  procName.value = Config.procNameList[route.name]
  getData()
})

const getData = async () => {
  if (procName.value.length > 0) {
    fetchForProcs(procName.value, {
      procName: procName.value[0],
      keyValues: params.value,
    })
  }
}

watchEffect(() => {
  if (results.value?.recordset?.length) {
    gameInfo.value.event = results.value.recordset[0]?.EventCode
    gameInfo.value.match = results.value.recordset[0]?.MatchName
    gameInfo.value.eventName = results.value.recordset[0]?.EventName
    if (results.value.recordset[0]?.MatchName.includes('现代五项')) {
      gameInfo.value.discipline = '现代五项'
      gameInfo.value.match = '马术'
      gameInfo.value.event = 'PENTATHLON'
      gameInfo.value.eventName = ''
    }
    irm.value = results.value.recordset[0]?.IRM
  }
})

watch(
  () => route.query,
  (val) => {
    params.value = val
    getData()
  }
)

watch(
  () => commonStore.receivedActionMessages,
  (newVal, oldVal) => {
    if (newVal.length > 0) {
      // const latestMsg = newVal[newVal.length - 1]
      getData()
    }
  },
  { deep: true }
)
</script>

<style scoped lang="scss">
@import '@/assets/scss/scb/warnUp';
</style>
